package m.jclecai.com.adapter.holder;

import android.content.Context;
import android.graphics.Color;
import android.text.TextUtils;
import android.view.View;
import android.widget.CheckedTextView;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import m.jclecai.com.R;
import m.jclecai.com.bean.RecordsBean;

/**
 * Created by zed on 2018/4/8.
 */

public class ChampionHolder extends ViewHolder {
    @BindView(R.id.ivTeamOne)
    ImageView ivTeamOne;
    @BindView(R.id.ivGjOne)
    ImageView ivGjOne;
    @BindView(R.id.tvTeamOne)
    CheckedTextView tvTeamOne;
    @BindView(R.id.ivTeamTwo)
    ImageView ivTeamTwo;
    @BindView(R.id.tvTeamTwo)
    CheckedTextView tvTeamTwo;
    @BindView(R.id.tvOdd)
    CheckedTextView tvOdd;
    @BindView(R.id.tvIndex)
    TextView tvIndex;
    @BindView(R.id.tvProbability)
    TextView tvProbability;
    @BindView(R.id.llParent)
    View llParent;
    @BindView(R.id.v_line)
    View v_line;
    @BindView(R.id.rlContainer)
    RelativeLayout rlContainer;


    public ChampionHolder(Context context, int resource) {
        super(context, resource);
    }

    public void initV1(int position, final RecordsBean bean) {
        String title = bean.getTitle();
        String index = (position < 10 ? "0" : "") + position;
        String[] ft = bean.getFilename().split(",");

        ivGjOne.setVisibility("1".equals(bean.getState()) ? VISIBLE : GONE);
        tvIndex.setText(index);
        tvTeamOne.setText(title);
        tvTeamOne.setVisibility(VISIBLE);
        tvTeamTwo.setVisibility(GONE);
        ivTeamTwo.setVisibility(GONE);
        Glide.with(getContext()).load(ft[0]).placeholder(R.mipmap.ic_cup_logo).into(ivTeamOne);

        if (title.contains("—")) {
            tvTeamOne.setVisibility(GONE);
            tvTeamTwo.setText(title);
            tvTeamTwo.setVisibility(VISIBLE);
        }

        if (ft.length > 1 && title.contains("—")) {
            ivTeamTwo.setVisibility(VISIBLE);
            Glide.with(getContext()).load(ft[1]).placeholder(R.mipmap.ic_cup_logo).into(ivTeamTwo);
        }
        tvProbability.setText(bean.getProbability());
        tvOdd.setText(bean.getOdds());

        if (TextUtils.isEmpty(bean.getIsclose())){
            llParent.setBackgroundColor(Color.parseColor("#ffffff"));
            tvProbability.setTextColor(Color.parseColor("#000000"));
            tvTeamTwo.setEnabled(true);
            tvTeamOne.setEnabled(true);
            tvOdd.setEnabled(true);
            setCheck(bean.isChecked());
        }else{
            if (bean.getIsclose().equals("1")){
                llParent.setBackgroundColor(Color.parseColor("#f8f8f8"));
                tvProbability.setTextColor(Color.parseColor("#CECECE"));
                tvTeamTwo.setEnabled(false);
                tvTeamOne.setEnabled(false);
                tvOdd.setEnabled(false);
            }else{
                llParent.setBackgroundColor(Color.parseColor("#ffffff"));
                tvProbability.setTextColor(Color.parseColor("#000000"));
                tvTeamTwo.setEnabled(true);
                tvTeamOne.setEnabled(true);
                tvOdd.setEnabled(true);
                setCheck(bean.isChecked());
            }
        }


    }

    public void setCheck(boolean check) {
        v_line.setBackgroundColor(Color.parseColor(check ? "#ffffff" : "#c5c4c3"));
        llParent.setBackgroundColor(Color.parseColor(check ? "#ef3c40" : "#ffffff"));
        tvOdd.setChecked(check);
        tvTeamOne.setChecked(check);
        tvTeamTwo.setChecked(check);

    }
}
